﻿using System.Windows;
using SHomeWorkshop.LunarPresentation.Interfaces;

namespace SHomeWorkshop.LunarPresentation.Commands
{
    public partial class Command
    {
        public static bool SwitchDocAutoWrap()
        {
            if (Globals.selectedEditor == null)
            {
                MessageBox.Show("未打开任何文档。", Globals.appName,
                    MessageBoxButton.OK, MessageBoxImage.Warning);
                return false;
            }

            bool newValue = !Globals.selectedEditor.AutoWrap;

            ModifingItem mi = new ModifingItem();
            Action action = new Action(null, -1, null, null,
                Globals.selectedEditor.AutoWrap.ToString(),
               newValue.ToString(), ActionType.AutoWrap, null);

            Globals.selectedEditor.AutoWrap = newValue;
            Globals.selectedEditor.IsModified = true;

            mi.Add(action);
            Globals.selectedEditor.Do(mi);
            return true;
        }

        public static void SwitchExAutoWrap(AutoWrapType newAutoWrapType)
        {
            if (Globals.selectedEditor == null) return;
            if (Globals.selectedEditor.SelectedExpression == null) return;
            if (Globals.selectedEditor.SelectedExpression is Expressions.BaseText)
            {
                Expressions.BaseText bt = Globals.selectedEditor.SelectedExpression as Expressions.BaseText;

                ModifingItem mi = new ModifingItem();
                Action actAutoWrap = new Action(bt.ExID, -1, bt.GetType().Name, "AutoWrap",
                    bt.AutoWrap.ToString(), newAutoWrapType.ToString());

                bt.AutoWrap = newAutoWrapType;

                mi.Add(actAutoWrap);
                bt.Editor.Do(mi);
                bt.Editor.IsModified = true;
            }
            else if (Globals.selectedEditor.SelectedExpression is Expressions.RichText)
            {
                Expressions.RichText rt = Globals.selectedEditor.SelectedExpression as Expressions.RichText;

                ModifingItem mi = new ModifingItem();
                Action actAutoWrap = new Action(rt.ExID, -1, rt.GetType().Name, "AutoWrap",
                    rt.AutoWrap.ToString(), newAutoWrapType.ToString());

                rt.AutoWrap = newAutoWrapType;

                mi.Add(actAutoWrap);
                rt.Editor.Do(mi);
                rt.Editor.IsModified = true;
            }
        }
    }
}
